
<html><HEAD>
<LINK REL=STYLESHEET HREF="default.css" TYPE="text/css">
<TITLE>
Saving data in an external file</TITLE>
</HEAD>
<BODY>

<!-- Header -->
<p class="ancestor" align="right"><A HREF="pbugp177.htm">Previous</A>&nbsp;&nbsp;<A HREF="pbugp179.htm" >Next</A>
<!-- End Header -->
<A NAME="BABFGBED"></A><h1>Saving data in an external file</h1>
<A NAME="TI5581"></A><p>While previewing, you can save the data retrieved in an external
file. Note that the data and headers (if specified) are saved. Information
in the footer or summary bands is not saved unless you are saving
as PDF or as a PSR file.</p>
<A NAME="TI5582"></A><p><img src="images/proc.gif" width=17 height=17 border=0 align="bottom" alt="Steps"> To save the data in a DataWindow object in an external
file:</p>
<ol><li class=fi><p>Select File&gt;Save Rows As from
the menu bar.</p><p>The Save As dialog box displays.</p></li>
<li class=ds><p>Choose a format for the file from the Save As
Type drop-down list.</p><p>If you want the column headers saved in the file, select a
file format that includes headers (such as Excel With Headers).
When you select a <i>with headers</i> format, the
names of the database columns (not the column labels) are also saved
in the file.</p><p>When you choose a format, PowerBuilder supplies the appropriate
file extension.</p></li>
<li class=ds><p>For TEXT, CSV, SQL, HTML, and DIF formats, select
an encoding for the file.</p><p>You can select ANSI/DBCS, Unicode LE (Little-Endian),
Unicode BE (Big-Endian), or UTF8.</p></li>
<li class=ds><p>Name the file and click Save.</p><p>PowerBuilder saves all displayed rows in the file; all columns
in the displayed rows are saved. Filtered rows are not saved.</p></li></ol>
<br><A NAME="TI5583"></A><p>The rest of this section provides more information
about saving data in PDF, HTML, and PSR formats.</p>
<A NAME="TI5584"></A><p>For more information about saving data as
XML, see <A HREF="pbugp245.htm#BABBABHD">Chapter 29, "Exporting and Importing
XML Data."</A></p>
<A NAME="BABHAFCGJK"></A><h2>Saving the data as PDF</h2>
<A NAME="TI5585"></A><p>PowerBuilder provides two ways to save a DataWindow object or DataStore
in Portable Document Format (PDF). </p>
<A NAME="TI5586"></A><h4>Using Ghostscript</h4>
<A NAME="TI5587"></A><p>By default, when you select File&gt;Save Rows As and
select PDF as the file type, the data is printed to a PostScript
file and automatically distilled to PDF using Ghostscript. This
option provides a robust solution that can save most types of DataWindow objects.</p>
<p><img src="images/note.gif" width=17 height=17 border=0 align="bottom" alt="Note"> <span class=shaded>Installing Ghostscript and PostScript drivers</span> <A NAME="TI5588"></A>For licensing reasons, Ghostscript and the PostScript drivers
required to use the distill method are not installed with PowerBuilder.
You (and your users) must download and install them before you can
use this technique. See <A HREF="pbugp178.htm#BABGIGHA">"System requirements for
the distill method"</A>. </p>
<A NAME="TI5589"></A><h4>Using XSL-FO and Java printing</h4>
<A NAME="TI5590"></A><p>Building on the ability to save data as XML, PowerBuilder can
also save the DataWindow object's data and presentation to PDF
by generating XSL Formatting Objects (XSL-FO). This option provides
a platform-independent solution by rendering the DataWindow using
a Java process rather than the Microsoft GDI. It also offers the
possibility of customizing the PDF file at the XSL-FO stage. Saving
as PDF using XSL-FO is particularly useful if you want to
print DataWindow objects in <ABBR title = "E A Server" >EAServer</ABBR> on
a UNIX operating system by using Java printing. The Ghostscript
method is not supported on UNIX.</p>
<A NAME="TI5591"></A><p>The XSL (Extensible Stylesheet Language) W3C Recommendation
has two parts, XSLT and XSL-FO. XSLT provides the transformation
typically used to present XML documents as HTML in a browser. XSL-FO
provides extensive formatting capabilities that are not dependent
on the output format. </p>
<A NAME="TI5592"></A><p>For more information about XSL, see the latest version of
the <A HREF="http://www.w3.org/TR/xsl/">Extensible Stylesheet Language (XSL)</A>
. </p>
<A NAME="TI5593"></A><h4>Limitations</h4>
<A NAME="TI5594"></A><p>The Ghostscript method currently does not support OLE and
RichText DataWindow objects. The XSL-FO method currently does not support OLE, RichText, graph,
and composite DataWindow objects.</p>
<A NAME="TI5595"></A><h3>Saving as PDF using the distill method</h3>
<A NAME="TI5596"></A><p>If you want to save to PDF using the distill method, you do
not need to change any properties. The distill method is used by
default when you select Save Rows As from the File menu in the DataWindow painter and
select PDF as the file type, or when you use the <b>SaveAs</b> method
with PDF! as the file type. </p>
<A NAME="TI5597"></A><p>PowerBuilder uses a PostScript printer driver specifically designed
for distilling purposes to configure the PDF output. You can choose
to use a different PostScript printer driver if you want to customize
your PostScript settings for generating PDF.</p>
<A NAME="TI5598"></A><h4>In the DataWindow painter</h4>
<A NAME="TI5599"></A><p>To use a custom PostScript printer driver, you must set some
properties.</p>
<A NAME="TI5600"></A><p><img src="images/proc.gif" width=17 height=17 border=0 align="bottom" alt="Steps"> To save customized distilled PDF output in the DataWindow painter:</p>
<ol><li class=fi><p>Select the Data Export tab in the Properties
view for the DataWindow object.</p></li>
<li class=ds><p>Select PDF from the Format to Configure drop-down
list, select Distill! from the Method drop-down list, and select
the Distill Custom PostScript check box.</p></li>
<li class=ds><p>Select the Print Specifications tab and specify
the name of the printer whose settings you want to use in the Printer
Name box.</p></li>
<li class=ds><p>Save the DataWindow object, then select File&gt;Save
Rows As, select PDF as the Save As Type, specify a file name, and
click Save.</p></li></ol>
<br><A NAME="TI5601"></A><h4>In a script</h4>
<A NAME="TI5602"></A><p>The properties you set in the DataWindow painter are saved
with the DataWindow object and are used by default when your application
runs, but for more control, specify the properties in a script before
saving the DataWindow object. To specify a custom printer driver
in a script, set the Export.PDF.Distill.CustomPostScript property
to Yes and specify a printer with the DataWindow.Printer property:<p><PRE> int li_ret<br> <br>dw_1.Object.DataWindow.Export.PDF.Method = Distill!<br>dw_1.Object.DataWindow.Printer = "\\prntsrvr\pr-6"<br>dw_1.Object.DataWindow.Export.PDF.  &amp;<br>   Distill.CustomPostScript="Yes"<br> <br>li_ret = dw_1.SaveAs("custom.PDF", PDF!, true)</PRE></p>
<A NAME="BABGIGHA"></A><h4>System requirements for
the distill method</h4>
<A NAME="TI5603"></A><p>Users must have administrative privileges to create a PDF
file.</p>
<A NAME="TI5604"></A><p>To support saving as PDF using Ghostscript, you must download
and install Ghostscript files on your system as described in the
chapter on deploying applications and components in <i>Application
Techniques</i>
<i></i>. You also need to install
PostScript driver files. </p>
<A NAME="TI5605"></A><p>If you have installed a PostScript printer on your computer,
the PostScript driver files required to create PDF files, <i>PSCRIPT5.DLL</i>, <i>PS5UI.DLL</i>,
and <i>pscript.ntf</i>, are already installed, typically
in <i>C:\WINDOWS\system32\spool\drivers\w32x86</i> on
Windows XP or <i>C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_1a216484\Amd64</i> on
a 64-bit Vista system. You must use the version of these files that
is appropriate to the operating system where the PDF file is created.
You should copy the files to the <i>Sybase\Shared\PowerBuilder\drivers</i> directory.</p>
<A NAME="TI5606"></A><p>If you have never installed a PostScript printer, use the
Printers and Faxes option in the Windows control panel to install
a generic PostScript printer. If the <i>Pscript5.dll</i> has
never been installed, you may be prompted to insert the Windows
install CD.</p>
<A NAME="TI5607"></A><p>Other related files are installed in <i>Sybase\Shared\PowerBuilder\drivers</i>. </p>
<A NAME="TI5608"></A><p>Saving as PDF fails at runtime on Windows 2003 Server. This
is caused by a Group Policy that by default disallows installation
of printers that use kernel-mode drivers. Kernel-mode drivers
have access to system-wide memory, and poorly written drivers can
cause system failures. To allow installation of kernel-mode drivers,
follow these steps:<A NAME="TI5609"></A>
<ol>
</li>
<li class=ds>Select
Run from the Windows Start menu.</li>
<li class=ds>In the Open box, type <FONT FACE="Courier New">gpedit.msc</FONT> and
click OK.</li>
<li class=ds>In the Group Policy console, expand Computer Configuration, Administrative
Templates, and Printers.</li>
<li class=ds>Disable "Disallow Installation of Printers
Using Kernel-Mode Drivers."
</li>
</ol>
</p>
<A NAME="TI5610"></A><p>When you deploy applications that use the ability to save
as PDF with the distill method, you must make sure your users have
installed Ghostscript and have access to the <i>drivers</i> directory. </p>
<A NAME="TI5611"></A><p>See the chapter on deployment in <i>Application Techniques</i>
 for
more information about redistributing these files.</p>
<A NAME="TI5612"></A><h3>Saving as PDF using XSL-FO</h3>
<A NAME="TI5613"></A><p>If you want to save to PDF using XSL-FO, you <i>must</i> set
one or more properties before saving.</p>
<A NAME="TI5614"></A><h4>In the DataWindow painter</h4>
<A NAME="TI5615"></A><p>In the DataWindow painter, you set PDF export properties on the Data
Export page in the Properties view.</p>
<A NAME="TI5616"></A><p><img src="images/proc.gif" width=17 height=17 border=0 align="bottom" alt="Steps"> To save PDF output using XSL-FO in the DataWindow painter:</p>
<ol><li class=fi><p>Select the Data Export tab in the Properties
view for the DataWindow object.</p></li>
<li class=ds><p>Select PDF from the Format to Configure drop-down
list and select XSLFOP! from the Method drop-down list.</p></li>
<li class=ds><p>(Optional) If you want simultaneously to send
the output directly to a printer using the Java printing option
of the Apache FOP processor, select the Print Using XSLFOP check
box.</p><br><img src="images/dwen34.gif"><br>
</li>
<li class=ds><p>Save the DataWindow object, then select File&gt;Save
Rows As, select PDF as the Save As Type, specify a file name, and
click Save.</p><p>PowerBuilder saves the data in the DataWindow object to the file you specified.
If you selected the Print Using XSLFOP check box, it also sends the
PDF file to the default printer for your system.</p></li></ol>
<br><A NAME="TI5617"></A><h4>In a script</h4>
<A NAME="TI5618"></A><p>In a script, set the Export.PDF.Method property to XSLFOP!
before saving the DataWindow object as PDF using the <b>SaveAs</b> method
with the SaveAsType PDF!. To send the PDF file directly to the default
printer, set the Export.PDF.XSLFOP.Print property to 1 or Yes before
saving:<p><PRE> int li_ret<br>dw_1.Modify("DataWindow.Export.PDF.Method = XSLFOP! ")<br>dw_1.Modify("DataWindow.Export.PDF.xslfop.print='1'")<br>li_ret = dw_1.SaveAs("printed.pdf", PDF!, true)</PRE></p>
<A NAME="BABDAHDG"></A><h3>Saving as XSL-FO</h3>
<A NAME="TI5619"></A><p>You can also save a DataWindow object as XSL-FO, then use the processor
of your choice to convert the XSL-FO string to the format you want,
applying your own customizations to the conversion. Processors such
as the Apache XSL Formatting Objects processor (FOP) can convert
XSL-FO documents into several output formats including PDF, PCL,
and AWT. </p>
<A NAME="TI5620"></A><p>In the DataWindow painter, select File&gt;Save Rows As and select
XSL-FO as the file type. In a script, you can use the <b>SaveAs</b> method
with the SaveAsType XSLFO!.</p>
<A NAME="TI5621"></A><p>For a DataWindow named <i>dwemp</i>, the following
command lines show the FOP syntax for producing a PDF, a print preview
rendered on screen (<FONT FACE="Courier New">-awt</FONT>),
and printable output rendered and sent to a printer (<FONT FACE="Courier New">-print</FONT>):<p><PRE> Fop dwemp.fo dwemp.pdf<br>Fop dwemp.fo -awt<br>Fop dwemp.fo -print</PRE></p>
<A NAME="TI5622"></A><p>For more information
about using FOP, see the <A HREF="http://xml.apache.org/fop/">FOP page of the Apache XML Project Web site</A>
.</p>
<A NAME="TI5623"></A><h3>System requirements for XSL-FO</h3>
<A NAME="TI5624"></A><p>The Apache XSL Formatting Objects processor (FOP) and the
Sun JDK are installed with PowerBuilder to support saving as XSL-FO,
saving as PDF using XSL-FO, and Java printing. Both are installed
in the <i>Sybase\Shared\PowerBuilder</i><i></i> directory. </p>
<A NAME="TI5625"></A><p>When you deploy applications that use XSL-FO or Java printing,
your users must have the FOP directory and the Java Runtime Environment
installed on their computers. For more information, see the chapter
on deploying your applications in <i>Application Techniques</i>.</p>
<A NAME="TI5626"></A><p>On Windows DBCS platforms, you also need to install a file
that supports DBCS characters to the Windows font directory, for
example, <i>C:\WINDOWS\fonts</i>.
To use these fonts, the <i>userconfig.xml </i>file
in the FOP <i>conf</i> directory must be modified
to give the full path name of the files you use, for example:<p><PRE> &lt;font metrics-file="C:\Program%20Files\Sybase\Shared\PowerBuilder\fop-0.20.4\conf\cyberbit.xml" kerning="yes" embed-file="C:\WINNT\Fonts\Cyberbit.ttf"&gt;</PRE></p>
<A NAME="TI5627"></A><p>For more information about configuring fonts, see the <A HREF="http://xml.apache.org/fop">Apache Web site</A>
. </p>
<A NAME="BFCCEFEG"></A><h2>Saving the data in HTML Table format</h2>
<A NAME="TI5628"></A><p>HTML Table format is one of the formats in which you can choose
to save data. When you save in HTML Table format, PowerBuilder saves
a style sheet along with the data. If you use this format, you can
open the saved file in a browser such as Internet Explorer. Once
you have the file in HTML Table format, you can continue to enhance
the file in HTML.</p>
<A NAME="TI5629"></A><h4>About the results</h4>
<A NAME="TI5630"></A><p>Some presentation styles translate better into HTML than others.
The Tabular, Group, Freeform, Crosstab, and Grid presentation styles
produce good results. The Composite, RichText, OLE 2.0, and Graph
presentation styles and nested reports produce HTML tables based
on the result set (data) only and not on the presentation style. DataWindows
with overlapping controls in them might not produce the results
you want.</p>
<A NAME="TI5631"></A><p><img src="images/proc.gif" width=17 height=17 border=0 align="bottom" alt="Steps"> To save a report as an HTML table:</p>
<ol><li class=fi><p>Open a DataWindow object.</p></li>
<li class=ds><p>Open the Preview view if it is not already open.</p></li>
<li class=ds><p>Select File&gt;Save Rows As from the menu bar.</p></li>
<li class=ds><p>Choose the HTML Table format for the file from the Save
As Type drop-down list.</p></li>
<li class=ds><p>Name the file.</p><p>PowerBuilder creates a file using the name you supplied and
the extension <i>htm</i>.</p></li>
<li class=ds><p>Open a Web browser.</p></li>
<li class=ds><p>Use the browser's file open command to open
the HTML file.</p></li></ol>
<br><A NAME="TI5632"></A><p>For more information about working with DataWindow objects
and HTML, see the <i>DataWindow Programmers Guide</i>
.</p>
<A NAME="CAICEIAE"></A><h2>Working with PSR files</h2>
<A NAME="TI5633"></A><p>A PSR file is a special file with the extension PSR created
by PowerBuilder, InfoMaker, or DataWindow Designer.</p>
<p><img src="images/note.gif" width=17 height=17 border=0 align="bottom" alt="Note"> <span class=shaded>Windows and PSR files</span> <A NAME="TI5634"></A>When PowerBuilder is installed, the PSR file type is registered
with Windows.</p>
<A NAME="TI5635"></A><p>A PSR file contains a DataWindow definition (source and object)
as well as the data contained in the DataWindow object when the PSR file
was created.</p>
<A NAME="TI5636"></A><caption><b>Figure 19-1: PSR file</b></captionls>
<br><img src="images/dwen12.gif">
<p><img src="images/note.gif" width=17 height=17 border=0 align="bottom" alt="Note"> <span class=shaded>About reports</span> <A NAME="TI5637"></A>A report is the same as a nonupdatable DataWindow object. For
more information, see <A HREF="pbugp161.htm#CDCFBFJF">"Reports versus DataWindow
objects"</A>.</p>
<A NAME="TI5638"></A><p>You can use a PSR file to save a complete report (report design
and data). This can be especially important if you need to keep
a snapshot of data taken against a database that changes frequently.</p>
<A NAME="TI5639"></A><p>PowerBuilder creates a PSR file when you save data in the Powersoft
report file format. See <A HREF="pbugp178.htm#BABFGBED">"Saving data in an external
file"</A>. PSR files are used primarily
by InfoMaker, a reporting tool. When an InfoMaker user opens a PSR
file, InfoMaker displays the report in the Report painter. If InfoMaker
is not already running, opening a PSR file automatically starts
InfoMaker.</p>
<A NAME="TI5640"></A><p>To open a PSR file in PowerBuilder, open any DataWindow object,
then select File&gt;Open File and select the PSR file.</p>

